package com.ruoyi.web.controller.emp;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EmpModelScheme;
import com.ruoyi.system.service.IEmpModelSchemeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型方案Controller
 *
 * @author zsl
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/system/scheme")
@Slf4j
public class EmpModelSchemeController extends BaseController {
    @Autowired
    private IEmpModelSchemeService empModelSchemeService;

    /**
     * 查询模型方案列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmpModelScheme empModelScheme) {
        startPage();
        List<EmpModelScheme> list = empModelSchemeService.selectEmpModelSchemeList(empModelScheme);
        return getDataTable(list);
    }

    /**
     * 导出模型方案列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:export')")
    @Log(title = "模型方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmpModelScheme empModelScheme) {
        List<EmpModelScheme> list = empModelSchemeService.selectEmpModelSchemeList(empModelScheme);
        log.info("导出模型方案列表:{}", JSON.toJSONString(list));
        ExcelUtil<EmpModelScheme> util = new ExcelUtil<EmpModelScheme>(EmpModelScheme.class);
        util.exportExcel(response, list, "模型方案数据");
    }

    /**
     * 获取模型方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(empModelSchemeService.selectEmpModelSchemeById(id));
    }

    /**
     * 新增模型方案
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:add')")
    @Log(title = "模型方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmpModelScheme empModelScheme) {
        return toAjax(empModelSchemeService.insertEmpModelScheme(empModelScheme));
    }

    /**
     * 修改模型方案
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:edit')")
    @Log(title = "模型方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmpModelScheme empModelScheme) {
        return toAjax(empModelSchemeService.updateEmpModelScheme(empModelScheme));
    }

    /**
     * 删除模型方案
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:remove')")
    @Log(title = "模型方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(empModelSchemeService.deleteEmpModelSchemeByIds(ids));
    }
}
